<?php

class doseyehComponents extends sfComponents {

    public function executeRelated() {

        $course = CourseTable::getInstance()
                ->createQuery('d')
                ->select('d.name_' . $this->culture)
                ->where("d.id=?", $this->course_id)
                ->fetchArray();

     
        $course_name = explode(' - ', $course[0]['name_en']);

        $this->items = CourseTable::getInstance()
                ->createQuery('c')
                ->select('d.course_id,d.name_en as name, d.cover_image, d.rating, c.name_en as inst_name, c.id')
                ->where("c.name_" . $this->culture . " LIKE ?", "%" . $course_name[0] . "%")
                ->andWhere("c.name_" . $this->culture . " NOT LIKE  ?", "%" . $course_name[1] . "%")
                ->leftJoin("c.Dos d")
                ->orderBy("Rand()")
                ->limit(3)
                ->fetchArray();
    }

    public function executeStats() {
        $this->univ = UniversityTable::getInstance()->count();
        $this->dos = DosTable::getInstance()->count();
        $this->students = sfGuardUserTable::getInstance()->createQuery()->where('is_super_admin = 0')->count();
    }

}